package com.pvdnc.nsocket.protocol;

import com.pvdnc.encrypt.IEncrypt;
import com.pvdnc.nsocket.serialize.ObjectStream;

public class EnInterpreter<T> extends Interpreter<T> {
    private final IEncrypt mEncryptor;

    public EnInterpreter(String command,IEncrypt encrypt) {
        super(command);
        mEncryptor=encrypt;
    }

    @Override
    public byte[] toData(T msg) {
        byte[] rawData= ObjectStream.toByte(msg);
        return mEncryptor.encrypt(rawData);
    }

    @Override
    public T fromByte(byte[] data) {
        byte[] rawData=mEncryptor.decrypt(data);
        return ObjectStream.fromByte(rawData);
    }
}
